package com.xjc.business.controller.stu;

import com.xjc.business.entity.po.stu.RepairApplyPo;
import com.xjc.business.entity.vo.stu.RepairApplyVo;
import com.xjc.business.service.StudentRepairApplysService;
import com.xjc.system.constants.MyConstants;
import com.xjc.system.exception.MyException;
import com.xjc.system.result.Result;
import com.xjc.system.result.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 徐锦程
 * 时间:2025-03-08 10:20
 */
@RestController
@RequestMapping("/student/repair_apply")
public class StuRepairApplyController {

    @Autowired
    StudentRepairApplysService studentRepairApplysService;

    /**
     * 添加报修申请
     * @param repairApplyPo 报修申请
     * @return 数据
     */
    @PostMapping("/add_repair_apply")
    public Result<String> addRepairApply(@RequestBody(required = false) RepairApplyPo repairApplyPo){
        if(repairApplyPo == null || repairApplyPo.getWxId() == null || repairApplyPo.getEquipment() == null || repairApplyPo.getLocation() == null || repairApplyPo.getInfo() == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }
        return studentRepairApplysService.addRepairApply(repairApplyPo);
    }

    /**
     * 获取当前报修申请
     * @param id 学生微信id
     * @return 数据
     */
    @GetMapping("/get_current_repair_apply/{id}")
    public Result<RepairApplyVo> getCurrentRepairApply(@PathVariable(required = false, value = "id") Integer id){
        if(id == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }
        return studentRepairApplysService.getCurrentRepairApply(id);
    }

    /**
     * 获取历史报修申请
     * @param id 学生微信id
     * @return 历史
     */
    @GetMapping("/get_history_repair_apply_list/{id}")
    public Result<List<RepairApplyVo>> getHistoryRepairApplyList(@PathVariable(required = false, value = "id") Integer id){
        if(id == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }
        return studentRepairApplysService.getHistoryRepairApplyList(id);
    }
}
